﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace park.System_Manager
{
    public partial class AuthorityRoleAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string method = Request.Params["method"];
                if (!string.IsNullOrEmpty(method))
                {
                    switch (method)
                    {
                        case "GetAuthorityItems":
                            {
                                GetAuthorityItems();
                                break;
                            }
                    }
                }
                // 因为修改和添加共用一个 js 文件，这句必需加上，要不然无法加载权限列表。
                Response.Write("<script>var authorityItems = \"\";</script>");
            }
        }

        private void GetAuthorityItems()
        {
            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
            
            string json = string.Empty;

            // json = sl.GetAuthorityItems();

            json = "{\"AuthorityItems\":[{\"id\":\"1\",\"name\":\"权限1\"},{\"id\":\"2\",\"name\":\"权限2\"},{\"id\":\"3\",\"name\":\"权限3\"},{\"id\":\"4\",\"name\":\"权限4\"},{\"id\":\"5\",\"name\":\"权限5\"},{\"id\":\"6\",\"name\":\"权限6\"},{\"id\":\"7\",\"name\":\"权限7\"},{\"id\":\"8\",\"name\":\"权限8\"},{\"id\":\"9\",\"name\":\"权限9\"},{\"id\":\"10\",\"name\":\"权限10\"},{\"id\":\"11\",\"name\":\"权限11\"},{\"id\":\"12\",\"name\":\"权限12\"},{\"id\":\"13\",\"name\":\"权限13\"},{\"id\":\"14\",\"name\":\"权限14\"},{\"id\":\"15\",\"name\":\"权限15\"},{\"id\":\"16\",\"name\":\"权限16\"},{\"id\":\"17\",\"name\":\"权限17\"},{\"id\":\"18\",\"name\":\"权限18\"},{\"id\":\"19\",\"name\":\"权限19\"},{\"id\":\"20\",\"name\":\"权限20\"},{\"id\":\"21\",\"name\":\"权限21\"},{\"id\":\"22\",\"name\":\"权限22\"},{\"id\":\"23\",\"name\":\"权限23\"}]}";

            Response.Write(json);
            Response.End();

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string roleName = this.txtRoleName.Text;
            string idList = this.hdf_SelectedAuthority.Value;
            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();

           // bool flag = sl.AddRole( roleName, idList);
            bool flag = true;

            string msg = flag ? "数据保存成功！" : "数据保存失败，请重试...";

            Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('" + msg + "');</script>");
        }
    }
}